<?php
//header("Content-Type", "UTF-8");
/**
 * @author paradox
 * @copyright 2012
 */


 
$search     = @$_GET["term"];
$country_id = @$_GET["country_id"];
$region_id  = @$_GET["region_id"];

$search = preg_replace("/[^a-zа-я -.]+/isu", '', $search);

if (!$search) die("[]");

include( "../../../../../configuration.php");

$conf = new JConfig;

$query = "SELECT * FROM `jos_tlog_city` WHERE `country_id`='$country_id' ". ( ($region_id) ? " AND `region_id`='$region_id' " : "" ) ." AND LCASE(`name`) LIKE LCASE('{$search}%')"; //

mysql_connect($conf->host,$conf->user,$conf->password);

mysql_query("SET NAMES 'utf8'");

mysql_selectdb($conf->db);

$rez = mysql_query($query);


$out = "";
$out1 = "";


while( $city = mysql_fetch_assoc($rez)) {
 

    if ($out) $out .= ",\n";
    $out  .= "   {\"id\":\"".$city["city_id"]."\",\"label\":\"".$city["name"]."\",\"value\":\"".$city["name"]."\"}";
    //[ { "id": "Aythya nyroca", "value": "Ferruginous Duck" } ]
    //$out1 .= "   '".$city["name"]."'";
}
//echo "<pre>";

echo "[ ";
echo $out;
echo "]\n\n";



//echo "var City_Names1 = [\n";
//echo $out1;
//echo "];\n\n";